package graph.day02;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Kama_100 {

    static int maxCount = 0;

    static int count = 0;

    static int[][] graph;

    static boolean[][] visited;

    static Queue<Integer> queue = new LinkedList<>();

    static int[][] direction = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        graph = new int[n][m];
        visited = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                graph[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (graph[i][j] == 1 && !visited[i][j]) {
                    count = 1;
                    bfs(i, j);
                    maxCount = Math.max(maxCount, count);
                }
            }
        }
        System.out.println(maxCount);
    }

    private static void bfs(int i, int j) {
        visited[i][j] = true;
        queue.offer(i);
        queue.offer(j);
        while (!queue.isEmpty()) {
            Integer x = queue.poll();
            Integer y = queue.poll();
            for (int[] dir : direction) {
                int nextX = x + dir[0];
                int nextY = y + dir[1];
                if (nextX < 0 || nextY < 0 || nextX >= graph.length || nextY >= graph[0].length) continue;
                if (graph[nextX][nextY] == 1 && !visited[nextX][nextY]) {
                    visited[nextX][nextY] = true;
                    count++;
                    queue.offer(nextX);
                    queue.offer(nextY);
                }
            }
        }

    }
}
